#ifndef COMMAND_LINE_HELPER_H
#define COMMAND_LINE_HELPER_H

#include <string>
#include <sstream>

bool ContainCommandlineKey (int argc, char **argv, std::string key);

bool FindCommandlineKey (int argc, char **argv, std::string key);

template <typename RET>
bool
ParseCommandlineArg (int argc, char **argv, std::string key, RET& value)
  {
  for (int i=0; i<argc; i++)
    {
    std::string arg (argv[i]);
    int pos = arg.find (key);

    if (pos == std::string::npos)
      {
      continue;
      }

    pos += key.size ();
    std::istringstream valueStr (arg.substr (pos));
    valueStr >> value;

    if (!valueStr && !valueStr.eof ())
      {
      return false;
      }
    else
      {
      return true;
      }
    }
  return false;
  }

#endif /* ifndef COMMAND_LINE_HELPER_H */
